package it.poste.il.compensatore.table;

import it.poste.il.compensatore.entity.Message;
import it.poste.il.compensatore.entity.MessageBody;
import it.poste.il.compensatore.entity.MessageStatus;
import it.poste.il.compensatore.entity.Operation;
import it.poste.il.compensatore.entity.SDPRequest;

import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

@SuppressWarnings("deprecation")
public class CreateTableOracle {
	public static void main(String[] args) {
		AnnotationConfiguration config = new AnnotationConfiguration();
		
		config.addAnnotatedClass(Message.class);
		config.addAnnotatedClass(MessageBody.class);
		config.addAnnotatedClass(MessageStatus.class);
		config.addAnnotatedClass(Operation.class);
		config.addAnnotatedClass(SDPRequest.class);

		config.configure("/META-INF/hibernate/hibernate.cfg.xml");
		
		//per creare la tabella sul DB
		new SchemaExport(config).create(true, true);
		
		//SessionFactory factory = config.buildSessionFactory(); 
		//ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry(); 
		//SessionFactory factory = config.buildSessionFactory(serviceRegistry);
		
		/*
		Configuration configuration = new Configuration();
	    configuration.configure();
	    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();        
	    SessionFactory factory = configuration.buildSessionFactory(serviceRegistry);
		*/
		
		/*
		session.beginTransaction();
		
		Message message = new Message();
		message.setId(11);
		message.setText("ciao");
		
		session.save(message);
		session.getTransaction().commit();
		*/
		
		/*
		Session session=HibernateUtil.getSessionFactory().openSession();
		Transaction tx=session.beginTransaction();
		
		Message message=new Message("Hello world");
		Long msgId=(Long) session.save(message);
		tx.commit();
		session.close();
		
		Session newSession=HibernateUtil.getSessionFactory().openSession();
		Transaction newTransaction=newSession.beginTransaction();
		
		List messages=newSession.createQuery("from Message m order by m.text asc").list();
		System.out.println();
		 */
	}
}